<!DOCTYPE html>
<html>
<body>
<input type="button" onclick="javascrtpt:window.location.href='/user/add'" value="添加">
<div id="loading" hidden="hidden"><img src="/images/loading.gif" width="20px">&nbsp;正在删除</div>
<table border="1">
    <tr>
        <th>账号</th>
        <th>昵称</th>
        <th>性别</th>
        <th>操作</th>
    </tr>
    <% for(var i = 0; i < list.length; i++) { %>
        <tr>
            <td><%= list[i].account %></td>
            <td><%= list[i].name %></td>
            <td>
                <%if(list[i].sex=="1" ){%> 男 <%}%>
                <%if(list[i].sex=="0" ){%> 女 <%}%>
            </td>
            <td>
                <a href="/user/<%= list[i]._id %>">修改</a>
                <%if(list[i]._id!=userId){%>
                    <button onclick="toDel('<%= list[i]._id %>');">删除</button>
                <%}%>
            </td>
        </tr>
    <% } %>
</table>
<script src="/javascripts/jquery-3.3.1.js"></script>
<script>
function toDel(id) {
    $("#loading").show();
    $.ajax({
        url: '/user/'+id,
        type: 'DELETE',
        success: function(result) {
            if(result.ret==0){
                window.location.reload();
            }else {
                alert("删除失败");
                $("#loading").hide();
            }
        }
    });
}
</script>
</body>
</html>